<?php 
namespace frontend\controllers;

use Yii;
use yii\web\Controller;
use frontend\models\Member;
use yii\web\UploadedFile;
/**
* 个人中心
*/
class MemberController extends Controller{
	public $layout='mymember';
	//我的申请
	public function actionMember_apply(){
		return $this->render('member_apply');
	}
	//展示简历
	public function actionMember_list(){
		$model=new Member();
		$cookie = \Yii::$app->request->cookies; 
        $cookie_data=$cookie->getValue('user');
        $id=$cookie_data[1];
        $sql="select * from recruit_resume";
        $connection = \Yii::$app->db;
        $command = $connection->createCommand($sql);
		$res = $command->queryAll();
		if($res){
			return $this->render('member_list',['res'=>$res]);
		}
		
	}
	//查看简历详细
	public function actionMember_resume(){
		$model = new Member();
		$id=$_GET['id'];
		//var_dump($id);die;
		$cookie = \Yii::$app->request->cookies; 
		$cookie_data=$cookie->getValue('user');
        $u_id=$cookie_data[1];
        //var_dump($u_id);die;
		$sql="select * from recruit_user inner join recruit_resume on recruit_user.id=recruit_resume.UserId where recruit_user.id=$u_id and recruit_resume.id=$id";
		//var_dump($model);die;
		$connection = \Yii::$app->db;
		$command = $connection->createCommand($sql);
		//var_dump($command);die;
		$res = $command->queryone();
		//var_dump($sql);die;
		$ids = $res['DesiredCityName'];
		$county_sql = " select name from recruit_region where id in($ids)";
		$start = $connection->createCommand($county_sql);
		$city_arr = $start->queryall();
		//var_dump($city_arr);die;
		foreach($city_arr as $v){
			$arr[]=$v['name'];
		}
		$res['DesiredCityName'] = implode(',',$arr);
		//var_dump($res);die;
		if($res){
			return $this->render('member_resume',['res'=>$res]);
		}
	}
	//已收藏职位
	public function actionMember_collect(){
		return $this->render('member_collect');
	}
	//账户设置
	public function actionMember_info(){
		$model=new Member();
		$request=Yii::$app->request;
		if($request->isPost){
			$post=$request->post();
			$model->photo = UploadedFile::getInstance($model, 'photo');
			$str = 'uploads/' . time() . rand(1111,9999) . '.' . $model->photo->extension;
	        $model->photo->saveAs($str);
	        $post['Member']['photo'] = $str;
			$res=$model->updateAll($post['Member'],['id'=>$post['Member']['id']]);
			$model=$model->find()->where(['id'=>$post['Member']['id']])->one();
		}
		return $this->render('member_info',['model'=>$model]);
	}
	//预览简历
	public function actionMember_review(){
		$id=$_GET['id'];
		//var_dump($id);die;
		$cookie = \Yii::$app->request->cookies; 
		$cookie_data=$cookie->getValue('user');
        $u_id=$cookie_data[1];
        //var_dump($u_id);die;
		$sql="select * from recruit_user inner join recruit_resume on recruit_user.id=recruit_resume.UserId where recruit_user.id=$u_id and recruit_resume.id=$id";
		//var_dump($model);die;
		$connection = \Yii::$app->db;
		$command = $connection->createCommand($sql);
		//var_dump($command);die;
		$data = $command->queryone();
		$ids = $data['DesiredCityName'];
		$county_sql = " select name from recruit_region where id in($ids)";
		$start = $connection->createCommand($county_sql);
		$city_arr = $start->queryall();
		//var_dump($city_arr);die;
		foreach($city_arr as $v){
			$arr[]=$v['name'];
		}
		$data['DesiredCityName'] = implode(',',$arr);
		return $this->render('member_review',['data'=>$data]);
	}
}



 ?>